﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Streaming_Service.Web.Helpers {
    public class RequestFunc {
        public static string GetParameter(HttpRequest request, string name, string defaultValue = "") {
            return request.Params[name] ?? defaultValue;
        }

        public static string GetQueryString(HttpRequest request, string name, string defaultValue = "") {
            return request.QueryString[name] ?? defaultValue;
        }

        public static int GetParameterInt(HttpRequest request, string name, int defaultValue = 0) {
            var val = GetParameter(request, name);
            int retVal;
            return int.TryParse(val, out retVal) ? retVal : defaultValue;
        }

        public static int GetQueryStringInt(HttpRequest request, string name, int defaultValue = 0) {
            var val = GetQueryString(request, name);
            int retVal;
            return int.TryParse(val, out retVal) ? retVal : defaultValue;
        }

        public static bool GetParameterBool(HttpRequest request, string name, bool defaultValue = false) {
            var val = GetParameter(request, name);
            return !String.IsNullOrEmpty(val) && (val == "1" || val == "y" || val == "yes");
        }

        public static bool GetQueryStringBool(HttpRequest request, string name, bool defaultValue = false) {
            var val = GetQueryString(request, name);
            return !String.IsNullOrEmpty(val) && (val == "1" || val == "y" || val == "yes");
        }
    }
}